import requests

# post 请求
# requests.post()

# get请求
# requests.get()

# 域名
host = "https://mall.deyunce.com/"
# login 接口地址
api_login = "api/account/login"
# 登录的完整的url地址
url_login = host + api_login

# 请求头信息
headers = {
    "content-type": "application/json",
    "Authorization": "Basic ZGV5dW5jZTo4MjgxMjM="
}

# 请求体信息
# 上载、上传、载荷
uploads = {
    "account": "13012312300",
    "password": "123456.",
    "client": 5
}

# 发送请求
res = requests.post(url=url_login, headers=headers, json=uploads)
# data 参数，正常情况，只接受表单数据
# json 参数，接受json格式的数据
# print(res)
# print(type(res))

# 查看响应信息
print(res.status_code)
# 查看响应提信息
print(res.text)  # 文本方式查看
print(res.json())  # json方式查看，转成字典形式了【必须响应是json格式才能使用】
# json解析错误  JSONDecodeError

print(res.content)  # 以二进制查看(字节码)

# 获取 msg、nickname、token的值
# print(type(res.json()))
res_json = res.json()  # 字典格式
msg = res_json["msg"]
print(f"msg = {msg}")

data = res_json["data"]
token = data["token"]
nickname = data["nickname"]
print(f"nickname = {nickname}")
print(f"token = {token}")

print(data.get("nickname11"))
